Setting "recommended" screen resolution automatically during OSD deployment?
Does anyone know of a way to set the screen resolution during an OSD task sequence to the "recommended" setting for Windows 7?  What I mean is if you go into the screen resolution control panel applet you will see one resolution in there with "(recommended)" next to it.  It would be nice to programatically set that during OSD deployment versus using answer files.
January 13th, 2010 7:32pm

As long as you have the video drivers injected correctly, and PnP vCard/Monitor (which they all are these days), Win7 (and WinXP for that matter) will automatically set the screen resolution to the native resolution of the monitor.  This is typically 1280x1024, unless it's a widescreen then it's dependant on the size, probably 720p or 1080p.
Free Windows Admin Tool Kit Click here and download it now
January 13th, 2010 8:04pm

Thanks Scott.  If that is the case with my MDT 2010 + SCCM R2 SP2 environment then somewhere in the files/task sequence created by the "Create Microsoft Deployment Task Sequence" it is being set to 1024x768.  Do you happen to know where I need to strip this out so it does it automagically?

January 13th, 2010 8:15pm

What size monitors do you have?  Some of the 17" and smaller older monitors are 1024x768 native.
Free Windows Admin Tool Kit Click here and download it now
January 13th, 2010 8:19pm

It supports higher resolutions.  After the OSD is complete I go into the screen resolution area and see the "recommended" which is higher than the 1024x768 that is set.  I am now under the assumption the resolution is coded in the MDT files.  I will look around.
January 13th, 2010 9:16pm

I wouldn't think something like the resolution would have anything to do with MDT.  Generally that information is in the sysprep.xml file on the system.  Have you tried looking at the sysprep file inside of the WIM file?
Free Windows Admin Tool Kit Click here and download it now
January 13th, 2010 10:50pm

I haven't tried looking in the WIM file yet.  I will mount it and look at it.  I have two sets of unattend.xml/customsettings.ini that I used in this deployment.  One for reference machine deployment and image capture.  The other for target machine deployment.  I tried removing all mention of 1024x768 from the target deployment unattend.xml but it still deploys at 1024x768.  Do I need to remove the 1024x768 from the reference machine unattend.xml?  That sounds counter-intuitive.
January 14th, 2010 4:33pm

you can force the resolution on the deployed sytem by editing the unattend.xml file in Windows SIM , and then saving that file, creating a package of that file and then using that unattend.xml file in the apply operating system image step within the task sequence.

settings pass = "oobeSystem "

component name = "Microsoft-Windows-Shell-Setup "
<Display>
<ColorDepth>16</ColorDepth>
<HorizontalResolution>1024</HorizontalResolution>
<RefreshRate>60</RefreshRate>
<VerticalResolution>768</VerticalResolution>
</Display>

for example ^

don't forget to update the dp with the new version of your unattend.xml file after making any changes,
you can verify the settings after deployment by reading the zticonfigure.log file

if you can't figure this out i can post an unattend.xml file for you to do just that, let me know


cheers
Free Windows Admin Tool Kit Click here and download it now
January 14th, 2010 5:33pm

i have been referencing an unattend.xml during my apply operating system image in the task sequence.  the original version of the file had a reference to 1024x768.  i removed that entry completely as i was under the impression if there is nothing in there then windows will automatically set the "recommended" setting.  would it be better for me to choose the highest resolution possible for all of my machines and then windows will choose the next appropriate lower resolution when deploying to a machine that can't handle that resolution?  i had read that is how it works somewhere on the interweb but am unsure if that is true.
January 14th, 2010 6:19pm

Did you set these properties somewhere initially when capturing the image (or before)?  I find it best not to specify such settings anywhere and Windows will just figure it out.
Free Windows Admin Tool Kit Click here and download it now
January 14th, 2010 7:15pm

I didn't specify a resolution.  I assume it was injected as part of MDT integration as MDT creates the unattend.xml?
January 14th, 2010 7:37pm

What hardware models are you building for? I am currently deploying Windows XP SP3 using ConfigMgr R2 SP2 with MDT 2010 and the resolution is set correctly for all Dell hardware but not HP hardware. For HP hardware I have installed SetRefresh which automatically sets the optimal resolution when the user logs in for the first time and this works well :)

Hope this helps.
Free Windows Admin Tool Kit Click here and download it now
January 15th, 2010 12:48am

Does anyone know of a way to set the screen resolution during an OSD task sequence to the "recommended" setting for Windows 7?  What I mean is if you go into the screen resolution control panel applet you will see one resolution in there with "(recommended)" next to it.  It would be nice to programatically set that during OSD deployment versus using answer files.

I have not used this in SCCM but I don't see why it wouldn't work.  I have had this script for a while and couldn't find the qres.exe commandline tool but I am sure you could easily find it in some dark corner of the internet.  If it needed to be adjusted to meet some additional requirements I would be willing to give you some assistance.


On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("localhost")
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DisplayConfiguration", "WQL", _
      wbemFlagReturnImmediately + wbemFlagForwardOnly)

   If objItem.PelsWidth <= 800 then
      set oShell = CreateObject("WScript.Shell")
      oShell.run"qres.exe /x 1024 /y 768"
   end if
   If objItem.BitsPerPixel < 32 then
      set oShell = CreateObject("WScript.Shell")
      oShell.run"qres.exe /c:32"
   end if
next

Mike Niccum

January 15th, 2010 2:35pm

Does anyone know of a way to set the screen resolution during an OSD task sequence to the "recommended" setting for Windows 7?  What I mean is if you go into the screen resolution control panel applet you will see one resolution in there with "(recommended)" next to it.  It would be nice to programatically set that during OSD deployment versus using answer files.

I have not used this in SCCM but I don't see why it wouldn't work.  I have had this script for a while and couldn't find the qres.exe commandline tool but I am sure you could easily find it in some dark corner of the internet.  If it needed to be adjusted to meet some additional requirements I would be willing to give you some assistance.


On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("localhost")
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DisplayConfiguration", "WQL", _
      wbemFlagReturnImmediately + wbemFlagForwardOnly)

   If objItem.PelsWidth <= 800 then
      set oShell = CreateObject("WScript.Shell")
      oShell.run"qres.exe /x 1024 /y 768"
   end if
   If objItem.BitsPerPixel < 32 then
      set oShell = CreateObject("WScript.Shell")
      oShell.run"qres.exe /c:32"
   end if
next

Mike Niccum

Free Windows Admin Tool Kit Click here and download it now
January 15th, 2010 2:35pm

I had the same problem... check your unattended.xml file for a specific resolution setting and try removing it. If a specific resolution is defined in unattended.xml, a newly deployed machine will use that by default. If nothing is specified, it should use the native resolution of the monitor if your driver is appropriate.
  • Proposed as answer by Josh Heffner Thursday, August 19, 2010 8:26 PM
March 18th, 2010 3:06pm

I had the same problem... check your unattended.xml file for a specific resolution setting and try removing it. If a specific resolution is defined in unattended.xml, a newly deployed machine will use that by default. If nothing is specified, it should use the native resolution of the monitor if your driver is appropriate.
  • Proposed as answer by Josh Heffner Thursday, August 19, 2010 8:26 PM
Free Windows Admin Tool Kit Click here and download it now
March 18th, 2010 3:06pm

Sorry to resurrect this.

What if you have different sized monitors all over the school? Even some laptops are different resolutions.
August 2nd, 2011 2:43am

Have you checked out the HP SetRefresh utility?
Free Windows Admin Tool Kit Click here and download it now
August 2nd, 2011 2:45am

No I haven't. Have you? If so, would you know how to set it up?

Would it work on non-HP computers as well?
August 2nd, 2011 4:03am

matambanadzo,

Did you find an answer to this?  I'm coming across the same issue!!

Free Windows Admin Tool Kit Click here and download it now
August 10th, 2011 10:01pm

Hi Alex,

No, no-one has provided a solution for me.

I ended up creating a task sequence for each different monitor size we have in the school. Then when it comes to imaging, we choose the task sequence that is the correct monitor size for the computer.

In the task sequences we have an application that applies the correct resolution (http://www.naughter.com/qres.html) at the end of the sequence

So the application command looks something like this ... resswitch.exe 1366 768 32 0

Instructions are included in the zip download from the site above.

 

August 11th, 2011 12:15am

You really shouldn't need to have seperate task sequences for each device.  First make sure you do not have driver conflicts by injecting only the INF files for the monitor attached to the system (see http://www.deployvista.com/Blog/JohanArwidmark/tabid/78/EntryID/132/language/en-US/Default.aspx for details, you would use scenario 3).  Also note that some monitors don't always detect properly in winPE, so you may have to choose the "Install all drivers from the profile" option.  Once you have verified that the right INF file is being injected for the right device, (check ztidrivers.log and pnpenum.xml) and it's still not working, verify that the unattend.xml is not setting it for you.  Use Windows System Image manager to edit the answer file to have the colordepth, refreshrate and resolution set to 1 (you can leave DPI blank). These setting are under 7 oobesystem\...shell setup\display.

 

I have tried this under MDT2010 update 1 under a plethora of IBM thinkpads and Dells

  • Proposed as answer by Jim_B Friday, August 19, 2011 2:33 PM
Free Windows Admin Tool Kit Click here and download it now
August 18th, 2011 7:09pm

You really shouldn't need to have seperate task sequences for each device.  First make sure you do not have driver conflicts by injecting only the INF files for the monitor attached to the system (see http://www.deployvista.com/Blog/JohanArwidmark/tabid/78/EntryID/132/language/en-US/Default.aspx for details, you would use scenario 3).  Also note that some monitors don't always detect properly in winPE, so you may have to choose the "Install all drivers from the profile" option.  Once you have verified that the right INF file is being injected for the right device, (check ztidrivers.log and pnpenum.xml) and it's still not working, verify that the unattend.xml is not setting it for you.  Use Windows System Image manager to edit the answer file to have the colordepth, refreshrate and resolution set to 1 (you can leave DPI blank). These setting are under 7 oobesystem\...shell setup\display.

 

I have tried this under MDT2010 update 1 under a plethora of IBM thinkpads and Dells

  • Proposed as answer by Jim_B Friday, August 19, 2011 2:33 PM
August 18th, 2011 7:09pm

No need to run a script to change the recommended resolution, the reason why this is happening is unattend.xml. 1024X768 is hard coded in MDT template unattend.xml. Display value needs to be deleted

  • Proposed as answer by TechOrion Wednesday, August 31, 2011 7:27 AM
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2011 3:37pm

No need to run a script to change the recommended resolution, the reason why this is happening is unattend.xml. 1024X768 is hard coded in MDT template unattend.xml. Display value needs to be deleted

  • Proposed as answer by TechOrion Wednesday, August 31, 2011 7:27 AM
August 19th, 2011 3:37pm

I'm having this issue with Windows 7 SP1 and SCCM's OSD. I'm not using MDT and I do not have a an unattend.xml file or a sysprep.ini file that my process is reading from.

The process was working fine prior to upgrading to SP1 using "Auto Apply Device Drivers". But since upgrading, I can get the right drivers installed, but the resolution is not being set to "recommended". It is being set to generally whatever is the lowest available setting. How can I have my build process always set the resolution to the recommended setting?

Free Windows Admin Tool Kit Click here and download it now
October 6th, 2011 8:59pm

Thanks Kubi. But how did you get to that view?

I've looked everywhere in MDT and cannot seem to get that view of the answer file.

 

EDIT: Never mind. I found out how. Task sequence properties then OS Info tab then Edit Unattend.xml button.


 

October 7th, 2011 2:38am

Thanks Kubi. But how did you get to that view?

I've looked everywhere in MDT and cannot seem to get that view of the answer file.

 

EDIT: Never mind. I found out how. Task sequence properties then OS Info tab then Edit Unattend.xml button.


 

Free Windows Admin Tool Kit Click here and download it now
October 7th, 2011 2:38am

I don't get the option in the screen shot above when I choose the Properties of a Task Sequence to Edit Unattend.xml. I don't even get an OS Info tab.

I still cannot find a hard-coded display setting in my environment, and the majority (not all) of models are coming up with 800x600. Something tells me it's the driver, but the same display drivers that were applying before SP1 are applying now.

I also opened my WIM file in WAIK and looked at the display settings are they are not configured.


October 7th, 2011 2:25pm

I don't get the option in the screen shot above when I choose the Properties of a Task Sequence to Edit Unattend.xml. I don't even get an OS Info tab.

I still cannot find a hard-coded display setting in my environment, and the majority (not all) of models are coming up with 800x600. Something tells me it's the driver, but the same display drivers that were applying before SP1 are applying now.

I also opened my WIM file in WAIK and looked at the display settings are they are not configured.


Free Windows Admin Tool Kit Click here and download it now
October 7th, 2011 2:25pm

@ William...

The answer Kubi gave is correct. Tried it out the other day and the deployment chose the correct resolution. But it takes a long time to mount the WIM for me to delete the Display option.

I'm not sure why you don't have the OS Info tab.... what version of Windows Server and MDT are you running? 

October 10th, 2011 1:12am

To resolve this I disabled Auto Apply Device Drivers in my SCCM task sequence, and manually created driver packages targeted to each model through a WMI query. My problem after I updated to W7 SP1 was that Auto Apply was applying generic display drivers as opposed to the "recommended" display driver for that model.

As an aside, a great tip I learned with Windows 7 is that after you've installed a needed driver via Device Manager, if you browse to C:\Windows\System32\DriverStore\FileRepository and sort by date, the driver that you just installed should be contained in a folder at the top of the window that will read or look something like this: amdsata.inf_amd64_neutral_67db50590108ebd9. You can copy that folder and it's contents to your SCCM Driver Source share, import it into SCCM from there, and you've now got only the driver(s) you actually need rather than a hodgepodge of best matched drivers that the OS may fault as not being boot critical.

Basic advice: Get away from Auto Apply Device Drivers and build driver packages targeted only to the models you use.

Free Windows Admin Tool Kit Click here and download it now
October 12th, 2011 7:43pm

HI,

I'm running sms sp2 r2 with mdt intergrated.

Using unattend.xml vai settings package at deployment time. (not even sure at this point if i need to). I want to set it to use the recommended settings for screen resolution.

How do i edit the xml? Is it safe to just delete the screen resolution settings and it will atuo pick it?

  <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
            <UserAccounts>
                <AdministratorPassword>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </AdministratorPassword>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Description>Temp account</Description>
                        <DisplayName>Temp account</DisplayName>
                        <Group>Users</Group>
                        <Name>TempAccount</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Enabled>true</Enabled>
                <Username>Administrator</Username>
                <Domain>.</Domain>
                <Password>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </Password>
                <LogonCount>999</LogonCount>
            </AutoLogon>
            <Display>
                <ColorDepth>32</ColorDepth>
                <HorizontalResolution>1024</HorizontalResolution>
                <RefreshRate>60</RefreshRate>
                <VerticalResolution>768</VerticalResolution>
            </Display>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>cscript.exe C:\MININT\Scripts\LiteTouch.wsf /start</CommandLine>
                  

March 12th, 2012 2:16pm

Yes it should be OK.
If you have MDT then you should be able to do the same method I did (above).

Deleting the Display section should also work in your "unattend.xml" file.

Free Windows Admin Tool Kit Click here and download it now
March 13th, 2012 12:16am

I'm having this issue with Windows 7 SP1 and SCCM's OSD. I'm not using MDT and I do not have a an unattend.xml file or a sysprep.ini file that my process is reading from.

The process was working fine prior to upgrading to SP1 using "Auto Apply Device Drivers". But since upgrading, I can get the right drivers installed, but the resolution is not being set to "recommended". It is being set to generally whatever is the lowest available setting. How can I have my build process always set the resolution to the recommended setting?

I have the same problem in which the correct driver installs, but the resolution will not set. Only when I choose to use an order driver does the resolution get set correctly. I do not have the resolution set in the Unattend.xml file and the setting Kubi posted above about it being hard coded into MDT does not apply either. It simply isn't in the unattend.xml file. Weird thing is this seems to only happen on the HP Elitebook 2730p models. We have other HP and Lenovo models running the same Win 7 x64 image I created with MDT and they all seem to work with no problems.

If I could, I would stay with the older driver, bu I need the newest driver to deal with external monitor detection issues on these tablets, so I guess I just have to fight with the resolution issue and see what I can come up with.

April 4th, 2012 5:31pm

So, for my problem which the HP Elitebook 2730p tablet with the proper resolution not being set after imaging with MDT turned out to be a drive issue. This appears to be a problem with the Mobile Intel 4 Express Chipset. Interl released a new driver a month or two ago and at first, I was having trouble with it, but I downloaded the zip file exreacted the files from it that way instead of running the exe and trying to find where to collect the same files.

One thing I did notice with doing this is that when the files are imported into the model driver foler in MDT, the "Application" files for GfxUi.exe, hkcmd.exe, igfxpers.exe and igfxtray.exe need to be unblocked. You can do this by right clikcing on the file name and going to Properties. At the bottom, you may see the button labeled "Unblock". I ran into this when imaging and the system applying the .2555 version driver would see these files as security issues because they were blocked. Once I unblocked them on the server and reimaged to test, the driver installed and ran beautifully. I even connected  an external monitor and got the message saying the optimal screen resolution for the external monitor should be 1024x768. I then did a "Scale to Full Screen" and both screen used the same resolution of the built-in display just as it should. I could disconnect/reconnect the external monitor and the same resolution was used each time. It looks as if this issue is finally solved.

I hope others have some luck with thier issues. 

Free Windows Admin Tool Kit Click here and download it now
April 9th, 2012 8:08pm

This worked for me (see URL below).  I have an HP 2760P tablet that kept defaulting to 1024x768.  I added the following two lines to my CustomSettings.ini file, and it fixed the problem.

XResolution=1280
YResolution=800

http://scriptimus.wordpress.com/2011/06/01/mdt-2010-configuring-the-native-screen-resolution/

Shawn

April 26th, 2012 6:08pm

Hi,

It didn't worked for me too, so i ended up writing a powershell script that does the work.

Copy/Paste the following function in a powershell script, and just call it without any parameter. I recommend also that you check if the target computer is not a VM (see the Check-VM function below)

Function Set-ScreenResolution {

$pinvokeCode = @"

using System;
using System.Runtime.InteropServices;

namespace Resolution
{

    [StructLayout(LayoutKind.Sequential)]
    public struct DEVMODE1
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmDeviceName;
        public short dmSpecVersion;
        public short dmDriverVersion;
        public short dmSize;
        public short dmDriverExtra;
        public int dmFields;

        public short dmOrientation;
        public short dmPaperSize;
        public short dmPaperLength;
        public short dmPaperWidth;

        public short dmScale;
        public short dmCopies;
        public short dmDefaultSource;
        public short dmPrintQuality;
        public short dmColor;
        public short dmDuplex;
        public short dmYResolution;
        public short dmTTOption;
        public short dmCollate;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmFormName;
        public short dmLogPixels;
        public short dmBitsPerPel;
        public int dmPelsWidth;
        public int dmPelsHeight;

        public int dmDisplayFlags;
        public int dmDisplayFrequency;

        public int dmICMMethod;
        public int dmICMIntent;
        public int dmMediaType;
        public int dmDitherType;
        public int dmReserved1;
        public int dmReserved2;

        public int dmPanningWidth;
        public int dmPanningHeight;
		
    };



    class User_32
    {
        [DllImport("user32.dll")]
        public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
        [DllImport("user32.dll")]
        public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);

        public const int ENUM_CURRENT_SETTINGS = -1;
        public const int CDS_UPDATEREGISTRY = 0x01;
        public const int CDS_TEST = 0x02;
        public const int DISP_CHANGE_SUCCESSFUL = 0;
        public const int DISP_CHANGE_RESTART = 1;
        public const int DISP_CHANGE_FAILED = -1;
    }


	
		
    public class PrmaryScreenResolution
    {
	
		static public void EnumerateSupportedModes()
		{
			DEVMODE1 dm = GetDevMode1();
			int modeIndex = 0;
			int maxWidth = 0;
			int maxHeight = 0;
			int maxFreq = 0;
			
			while (0 != User_32.EnumDisplaySettings(null, modeIndex, ref dm))
			{
				maxWidth = dm.dmPelsWidth;
				maxHeight = dm.dmPelsHeight;
				maxFreq = dm.dmDisplayFrequency;
				//Console.WriteLine(maxWidth + "*" + maxHeight + "/" + maxFreq);
				modeIndex++;
			}
			Console.WriteLine("Detected Native Screen Resolution : " + maxWidth + "*" + maxHeight + "/" + maxFreq);
			
		}
		
        static public string ChangeResolution()
        {

            DEVMODE1 dm = GetDevMode1();
			// Autodetection
			int modeIndex = 0;
			int maxWidth = 0;
			int maxHeight = 0;
			int maxFreq = 0;
			
			while (0 != User_32.EnumDisplaySettings(null, modeIndex, ref dm))
			{
				maxWidth = dm.dmPelsWidth;
				maxHeight = dm.dmPelsHeight;
				maxFreq = dm.dmDisplayFrequency;
				modeIndex++;
			}
			Console.WriteLine("Detected screen's native resolution : " + maxWidth + "*" + maxHeight + "/" + maxFreq + "Hz");
						
			
            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {
						
                //dm.dmPelsWidth = width;
                //dm.dmPelsHeight = height;
				
				//Checking if current resolution and frequency is already to maximum
				
				int currentWidth = 0;
				int currentHeight = 0;
				int currentFreq = 0;
				currentWidth = dm.dmPelsWidth;
				currentHeight = dm.dmPelsHeight;
				currentFreq = dm.dmDisplayFrequency;
				
				if ((currentWidth == maxWidth) && (currentHeight == maxHeight) && (currentFreq == maxFreq))
				{
					return "Current resolution and frequency is already to maximum : no change to be made";
				}
				else
				{
					//Setting to the screen's native resolution and frequency
					dm.dmPelsWidth = maxWidth;
					dm.dmPelsHeight = maxHeight;
					dm.dmDisplayFrequency = maxFreq;
					Console.WriteLine ("Current resolution is " + currentWidth + "*" + currentHeight + "/" + currentFreq + "Hz");
					Console.WriteLine ("Setting new resolution to " + maxWidth + "*" + maxHeight + "/" + maxFreq + "Hz");
					
					int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);

					if (iRet == User_32.DISP_CHANGE_FAILED)
					{
						return "Unable To Process Your Request. Sorry For This Inconvenience.";
					}
					else
					{
						iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
						switch (iRet)
						{
							case User_32.DISP_CHANGE_SUCCESSFUL:
								{
									return "Success";
								}
							case User_32.DISP_CHANGE_RESTART:
								{
									return "You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode.";
								}
							default:
								{
									return "Failed To Change The Resolution";
								}
						}

					}


				}
			}
			else
			{
				return "Failed To Change The Resolution.";
			}
		
				
        }

        private static DEVMODE1 GetDevMode1()
        {
            DEVMODE1 dm = new DEVMODE1();
            dm.dmDeviceName = new String(new char[32]);
            dm.dmFormName = new String(new char[32]);
            dm.dmSize = (short)Marshal.SizeOf(dm);
            return dm;
        }
    }
}

"@

Add-Type $pinvokeCode -ErrorAction SilentlyContinue
[Resolution.PrmaryScreenResolution]::ChangeResolution()

}

Function Check-VM{
	Write-Output "Checking if host is a VM"

	$VM_Count = 0
	#Searching for specific VM processes
	Get-process | Where-Object { ($_.ProcessName -like "VBoxService") -or ($_.ProcessName -like "VBoxTray") -or ($_.ProcessName -like "VMwareTray") -or ($_.ProcessName -like "VMwareUser")}
	If ($process_list -ne $Null) {$VM_Count += 1}

	#Checking Bios Informations
	$Bios_info = Get-WmiObject Win32_BIOS
	If (($Bios_info.SMBIOSBIOSVersion -like "*virt*") -or ($Bios_info.Version -like "*Vbox*")) {$VM_Count += 1}

	#Checking Baseboard
	$Baseboard_info = Get-WmiObject Win32_Baseboard
	If ($Baseboard_info.Product -like "*440BX Desktop Reference Platform*") {$VM_Count += 1}

	#Checking HDD
	$HDD_info = Get-WmiObject Win32_DiskDrive
	If (($HDD_info.Model -like "*VBOX*") -or ($HDD_info.Model -like "*VMWARE VIRTUAL*")) {$VM_Count += 1}

	If ($VM_Count -ge 2) {
		return $true
	}
	Else {
		return $false
	}

}


Free Windows Admin Tool Kit Click here and download it now
March 19th, 2013 1:24pm

Hi,

It didn't worked for me too, so i ended up writing a powershell script that does the work.

Copy/Paste the following function in a powershell script, and just call it without any parameter. I recommend also that you check if the target computer is not a VM (see the Check-VM function below)

Function Set-ScreenResolution {

$pinvokeCode = @"

using System;
using System.Runtime.InteropServices;

namespace Resolution
{

    [StructLayout(LayoutKind.Sequential)]
    public struct DEVMODE1
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmDeviceName;
        public short dmSpecVersion;
        public short dmDriverVersion;
        public short dmSize;
        public short dmDriverExtra;
        public int dmFields;

        public short dmOrientation;
        public short dmPaperSize;
        public short dmPaperLength;
        public short dmPaperWidth;

        public short dmScale;
        public short dmCopies;
        public short dmDefaultSource;
        public short dmPrintQuality;
        public short dmColor;
        public short dmDuplex;
        public short dmYResolution;
        public short dmTTOption;
        public short dmCollate;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
        public string dmFormName;
        public short dmLogPixels;
        public short dmBitsPerPel;
        public int dmPelsWidth;
        public int dmPelsHeight;

        public int dmDisplayFlags;
        public int dmDisplayFrequency;

        public int dmICMMethod;
        public int dmICMIntent;
        public int dmMediaType;
        public int dmDitherType;
        public int dmReserved1;
        public int dmReserved2;

        public int dmPanningWidth;
        public int dmPanningHeight;
		
    };



    class User_32
    {
        [DllImport("user32.dll")]
        public static extern int EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE1 devMode);
        [DllImport("user32.dll")]
        public static extern int ChangeDisplaySettings(ref DEVMODE1 devMode, int flags);

        public const int ENUM_CURRENT_SETTINGS = -1;
        public const int CDS_UPDATEREGISTRY = 0x01;
        public const int CDS_TEST = 0x02;
        public const int DISP_CHANGE_SUCCESSFUL = 0;
        public const int DISP_CHANGE_RESTART = 1;
        public const int DISP_CHANGE_FAILED = -1;
    }


	
		
    public class PrmaryScreenResolution
    {
	
		static public void EnumerateSupportedModes()
		{
			DEVMODE1 dm = GetDevMode1();
			int modeIndex = 0;
			int maxWidth = 0;
			int maxHeight = 0;
			int maxFreq = 0;
			
			while (0 != User_32.EnumDisplaySettings(null, modeIndex, ref dm))
			{
				maxWidth = dm.dmPelsWidth;
				maxHeight = dm.dmPelsHeight;
				maxFreq = dm.dmDisplayFrequency;
				//Console.WriteLine(maxWidth + "*" + maxHeight + "/" + maxFreq);
				modeIndex++;
			}
			Console.WriteLine("Detected Native Screen Resolution : " + maxWidth + "*" + maxHeight + "/" + maxFreq);
			
		}
		
        static public string ChangeResolution()
        {

            DEVMODE1 dm = GetDevMode1();
			// Autodetection
			int modeIndex = 0;
			int maxWidth = 0;
			int maxHeight = 0;
			int maxFreq = 0;
			
			while (0 != User_32.EnumDisplaySettings(null, modeIndex, ref dm))
			{
				maxWidth = dm.dmPelsWidth;
				maxHeight = dm.dmPelsHeight;
				maxFreq = dm.dmDisplayFrequency;
				modeIndex++;
			}
			Console.WriteLine("Detected screen's native resolution : " + maxWidth + "*" + maxHeight + "/" + maxFreq + "Hz");
						
			
            if (0 != User_32.EnumDisplaySettings(null, User_32.ENUM_CURRENT_SETTINGS, ref dm))
            {
						
                //dm.dmPelsWidth = width;
                //dm.dmPelsHeight = height;
				
				//Checking if current resolution and frequency is already to maximum
				
				int currentWidth = 0;
				int currentHeight = 0;
				int currentFreq = 0;
				currentWidth = dm.dmPelsWidth;
				currentHeight = dm.dmPelsHeight;
				currentFreq = dm.dmDisplayFrequency;
				
				if ((currentWidth == maxWidth) && (currentHeight == maxHeight) && (currentFreq == maxFreq))
				{
					return "Current resolution and frequency is already to maximum : no change to be made";
				}
				else
				{
					//Setting to the screen's native resolution and frequency
					dm.dmPelsWidth = maxWidth;
					dm.dmPelsHeight = maxHeight;
					dm.dmDisplayFrequency = maxFreq;
					Console.WriteLine ("Current resolution is " + currentWidth + "*" + currentHeight + "/" + currentFreq + "Hz");
					Console.WriteLine ("Setting new resolution to " + maxWidth + "*" + maxHeight + "/" + maxFreq + "Hz");
					
					int iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_TEST);

					if (iRet == User_32.DISP_CHANGE_FAILED)
					{
						return "Unable To Process Your Request. Sorry For This Inconvenience.";
					}
					else
					{
						iRet = User_32.ChangeDisplaySettings(ref dm, User_32.CDS_UPDATEREGISTRY);
						switch (iRet)
						{
							case User_32.DISP_CHANGE_SUCCESSFUL:
								{
									return "Success";
								}
							case User_32.DISP_CHANGE_RESTART:
								{
									return "You Need To Reboot For The Change To Happen.\n If You Feel Any Problem After Rebooting Your Machine\nThen Try To Change Resolution In Safe Mode.";
								}
							default:
								{
									return "Failed To Change The Resolution";
								}
						}

					}


				}
			}
			else
			{
				return "Failed To Change The Resolution.";
			}
		
				
        }

        private static DEVMODE1 GetDevMode1()
        {
            DEVMODE1 dm = new DEVMODE1();
            dm.dmDeviceName = new String(new char[32]);
            dm.dmFormName = new String(new char[32]);
            dm.dmSize = (short)Marshal.SizeOf(dm);
            return dm;
        }
    }
}

"@

Add-Type $pinvokeCode -ErrorAction SilentlyContinue
[Resolution.PrmaryScreenResolution]::ChangeResolution()

}

Function Check-VM{
	Write-Output "Checking if host is a VM"

	$VM_Count = 0
	#Searching for specific VM processes
	Get-process | Where-Object { ($_.ProcessName -like "VBoxService") -or ($_.ProcessName -like "VBoxTray") -or ($_.ProcessName -like "VMwareTray") -or ($_.ProcessName -like "VMwareUser")}
	If ($process_list -ne $Null) {$VM_Count += 1}

	#Checking Bios Informations
	$Bios_info = Get-WmiObject Win32_BIOS
	If (($Bios_info.SMBIOSBIOSVersion -like "*virt*") -or ($Bios_info.Version -like "*Vbox*")) {$VM_Count += 1}

	#Checking Baseboard
	$Baseboard_info = Get-WmiObject Win32_Baseboard
	If ($Baseboard_info.Product -like "*440BX Desktop Reference Platform*") {$VM_Count += 1}

	#Checking HDD
	$HDD_info = Get-WmiObject Win32_DiskDrive
	If (($HDD_info.Model -like "*VBOX*") -or ($HDD_info.Model -like "*VMWARE VIRTUAL*")) {$VM_Count += 1}

	If ($VM_Count -ge 2) {
		return $true
	}
	Else {
		return $false
	}

}


March 19th, 2013 1:24pm

Well that didn't work...

Free Windows Admin Tool Kit Click here and download it now
May 6th, 2014 3:34am

Well that didn't work...

May 6th, 2014 3:34am

HI,

I'm running sms sp2 r2 with mdt intergrated.

Using unattend.xml vai settings package at deployment time. (not even sure at this point if i need to). I want to set it to use the recommended settings for screen resolution.

How do i edit the xml? Is it safe to just delete the screen resolution settings and it will atuo pick it?

  <settings pass="oobeSystem">
        <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">
            <UserAccounts>
                <AdministratorPassword>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </AdministratorPassword>
                <LocalAccounts>
                    <LocalAccount wcm:action="add">
                        <Description>Temp account</Description>
                        <DisplayName>Temp account</DisplayName>
                        <Group>Users</Group>
                        <Name>TempAccount</Name>
                    </LocalAccount>
                </LocalAccounts>
            </UserAccounts>
            <AutoLogon>
                <Enabled>true</Enabled>
                <Username>Administrator</Username>
                <Domain>.</Domain>
                <Password>
                    <Value></Value>
                    <PlainText>true</PlainText>
                </Password>
                <LogonCount>999</LogonCount>
            </AutoLogon>
            <Display>
                <ColorDepth>32</ColorDepth>
                <HorizontalResolution>1024</HorizontalResolution>
                <RefreshRate>60</RefreshRate>
                <VerticalResolution>768</VerticalResolution>
            </Display>
            <FirstLogonCommands>
                <SynchronousCommand wcm:action="add">
                    <CommandLine>cscript.exe C:\MININT\Scripts\LiteTouch.wsf /start</CommandLine>
                  

You can literally just delete the entire section that I bolded, underlined, and put in Italic.  At least that's what I did for my x86 image and it worked.
Free Windows Admin Tool Kit Click here and download it now
June 4th, 2015 1:47pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics